#!/usr/bin/env python
#coding=utf-8
"""
socket server ex1
"""
import socket
host = '127.0.0.1'
port = 52333

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.bind((host, port))

s.listen(1)

while 1:
	conn, addr = s.accept()

	while 1:
		data = conn.recv(1024)	#接受1024字节
		print 'recv', data

		#如果客户端被关闭，跳出循环
		if not data: break

		data_new = data.upper()

		conn.sendall(data_new)
		print 'send', data_new

	conn.close()